<!--*********************************************************************************
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
*
 ********************************************************************************/
-->
<!-- BEGIN: main -->
<script language="javascript">
function addtopricebook()
{
	x = document.addToPB.selected_id.length;
	prod_array = new Array(x);
	idstring = "";
	if ( x == undefined)
	{
		if (document.addToPB.selected_id.checked)
		{
			yy = document.addToPB.selected_id.value+"_listprice";
			document.addToPB.idlist.value=document.addToPB.selected_id.value;
			var elem = document.addToPB.elements;
			var ele_len =elem.length;
			var i=0,j=0;
	
			for(i=0; i<ele_len; i++)
			{	
				if(elem[i].name == yy)
				{
					if (elem[i].value.replace(/^\s+/g, '').replace(/\s+$/g, '').length==0) 
					{
						alert("List Price cannot be empty");
			               		return false;	
					}	
					else if(isNaN(elem[i].value))
                                        {
                                                alert("Invalid List Price");
                                                return false;
                                        }

				}
			}	
			
		}
		else 
		{
			alert("Please select at least one entity");
			return false;
		}
	}
	else
	{
		xx = 0;
		for(i = 0; i < x ; i++)
		{
			if(document.addToPB.selected_id[i].checked)
			{
				idstring = document.addToPB.selected_id[i].value +";"+idstring;
				 prod_array[xx] = document.addToPB.selected_id[i].value;
				
				xx++;	
			}
		}
		if (xx != 0)
		{
			document.addToPB.idlist.value=idstring;
			var elem = document.addToPB.elements;
                        var ele_len =elem.length;
                        var i=0,j=0;

                        for(i=0; i<ele_len; i++)
                        {
                                for(j=0; j < xx; j++)
                                {
                                        var xy= prod_array[j]+"_listprice";
                                        if(elem[i].name == xy)
                                        {
						if (elem[i].value.replace(/^\s+/g, '').replace(/\s+$/g, '').length==0) 
						{
							alert("List Price cannot be empty");
			                		return false;	
						}
						else if(isNaN(elem[i].value))
                	                        {
        	                                        alert("Invalid List Price");
                                                	return false;
                                        	}
	
                                        }
                                }
                        }

		}
		else
		{
			alert("Please select at least one entity");
			return false;
		}
	}
document.addToPB.action="index.php?module=Products&action=addPbProductRelToDB&return_module=Products&return_action=DetailView&return_id={RETURN_ID}"
}


function updateAllListPrice(unitprice)
{
        var fieldname_array = new Array({FIELD_NAME_ARRAY});
        var unitprice,fieldname;

        for(j=0; j<fieldname_array.length; j++)
        {
                fieldname=fieldname_array[j];
                updateListPrice(unitprice,fieldname);
        }
}

</script>
<script language="javascript" src="modules/Products/Products.js"></script>
<table width="95%" border="0" cellpadding="0" cellspacing="0">
<tr><td colspan="3">&nbsp;</td></tr>
<tr>
		<td>&nbsp;</td>
		<td class="showPanelBg">
{PRICEBOOKLISTHEADER}
<table border="0" cellpadding="0" cellspacing="0"  width="100%">
  <tr height="20"> 
    <td  class="listFormHeaderLinks">
	 <table border="0" cellpadding="0" cellspacing="0" width="100%">
		<tr>
			<td>&nbsp;{RECORD_COUNTS}</td>
			   {NAVIGATION}
		</tr>
	 </table>
    </td>
   </tr>
   <tr>
   			<td>
					<table style="background-color: rgb(204, 204, 204);" class="small" border="0" cellpadding="3" cellspacing="1" width="90%" align="center">
							 {LISTHEADER}
							 {LISTENTITY}
					</table>
			</td>
   </tr>   
   <tr><td>&nbsp;</td></tr>
   </form>
</table>

<!-- END: main -->
</form>
</table>
</td>
<td>&nbsp;</td>
</tr>
</table>

